package com.sise.bl.utils.converter;


import org.springframework.core.convert.converter.Converter;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class MyStringToDateConvert implements Converter<String, Date> {

    //数据类型转换，将String类型转换为Date
    @Override
    public Date convert(String s) {
        Date date = null;
        if (s == null) {
            throw new RuntimeException("请传入数据");
        } else {
            DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            try {
                format.parse(s);
            } catch (ParseException e) {
                System.out.println("数据类型转换错误");
                e.printStackTrace();
            }
        }
        return date;
    }
}
